package mainScreen;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

import mainScreen.MainPage.MainPanel;

//import mainScreen.MainPage.MainPanel;

public class AdminFunctions extends JFrame {
	JFrame mainFrame;
	AdminFunctionsMainPanel AdminTitlePanel, AdminFunctionPanel, leftPanel, AdminDisplayPanel, bottomPanel;
	JTextArea AdminDisplay = new JTextArea();
	JButton AdminClear = new JButton("Clear Display Area");
	
	public AdminFunctions()
	{
		mainFrame = new JFrame("Administratior Functions");
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainFrame.setPreferredSize(new Dimension(500,400));
		setLayout(new BorderLayout());
		
		AdminTitlePanel = new AdminFunctionsMainPanel(Color.RED);
		AdminTitlePanel.setPreferredSize(new Dimension(50,75));
		AdminTitlePanel.setBorder(BorderFactory.createMatteBorder(9, 9, 9, 9, Color.black));
		AdminTitlePanel.setAdminTitlePanel();
		
		leftPanel = new AdminFunctionsMainPanel(Color.red);
		leftPanel.setBorder(BorderFactory.createMatteBorder(0, 8, 0, 8, Color.black));
		//leftPanel.setPreferredSize(new Dimension(50,75));
		//leftPanel.setLeftPanel();
		
		AdminDisplayPanel = new AdminFunctionsMainPanel(Color.white);
		AdminDisplayPanel.setPreferredSize(new Dimension(600,600));
		AdminDisplayPanel.setBorder(BorderFactory.createMatteBorder(0, 8, 0, 0, Color.black));
		AdminDisplayPanel.setAdminDisplayPanel();
		
		bottomPanel = new AdminFunctionsMainPanel(Color.red);
		bottomPanel.setBorder(BorderFactory.createMatteBorder(8, 0, 8, 0, Color.black));
		
		AdminFunctionPanel = new AdminFunctionsMainPanel(Color.pink);
		AdminFunctionPanel.setFunctionPanel();
				
		Container contentPane = mainFrame.getContentPane();
		contentPane.add(AdminTitlePanel, BorderLayout.NORTH);
		contentPane.add(leftPanel, BorderLayout.WEST);
		contentPane.add(AdminDisplayPanel, BorderLayout.EAST);
		contentPane.add(bottomPanel, BorderLayout.SOUTH);
		contentPane.add(AdminFunctionPanel, BorderLayout.CENTER);
		
		
		mainFrame.pack();
        mainFrame.setVisible(true);
		
	}
	
	private class AdminButtonHandler1 implements ActionListener
    {
		public void actionPerformed( ActionEvent event )
   	 	{
			AdminDisplay.append("You pressed:" +event.getActionCommand() + "\n");
			JOptionPane.showMessageDialog( null,
		            "You pressed:" + event.getActionCommand() );
    
   	 	}
   	 
    }
	
	private class AdminButtonHandler2 implements ActionListener
	{
		public void actionPerformed( ActionEvent event )
   	 	{
			String logout = "LogOut";
			JOptionPane.showMessageDialog( null,
		            "You have been successfully logged Out" );
			String cmd = event.getActionCommand();
			if (cmd.equals(logout))
				setVisible(false);
				mainFrame.dispose();
				
    
   	 	}
		
	}
	
	private class AdminButtonHandler3 implements ActionListener
	{
		public void actionPerformed( ActionEvent event )
		{
			String s = "";
			AdminDisplay.setText(s);
       	}
	}
	
	class AdminFunctionsMainPanel extends JPanel
	{
		JLabel mainLbl;
		JButton membercnt, itemschkdout, finesCollected, itemsByCategory, bookCheckedOutMost, logout;
		AdminButtonHandler1 handler1, handler2, handler3, handler4, handler5;
		AdminButtonHandler2 handler6;
		AdminButtonHandler3 handler7;
		
		
		
		public AdminFunctionsMainPanel(Color color)
		{
			setBackground(color);
			
			//create instances for buttons
			membercnt = new JButton("Total Number Of Members");
			itemschkdout = new JButton("Items Checked Out");
			finesCollected = new JButton("Fines Collected");
			itemsByCategory = new JButton("List Of Items By Category");
			bookCheckedOutMost = new JButton("Books Checked Out The Most");
			logout = new JButton("LogOut");
			
			//create instances for button handler
			handler1 = new AdminButtonHandler1();
			handler2 = new AdminButtonHandler1();
			handler3 = new AdminButtonHandler1();
			handler4 = new AdminButtonHandler1();
			handler5 = new AdminButtonHandler1();
			handler6 = new AdminButtonHandler2();
			handler7 = new AdminButtonHandler3();
			
			membercnt.addActionListener(handler1);
			itemschkdout.addActionListener(handler2);
			finesCollected.addActionListener(handler3);
			itemsByCategory.addActionListener(handler4);
			bookCheckedOutMost.addActionListener(handler5);
			logout.addActionListener(handler6);
			AdminClear.addActionListener(handler7);
				
		}
		
		public void setAdminTitlePanel()
		{
			mainLbl = new JLabel("ADMINISTRATOR FUNCTIONS");
			mainLbl.setFont(new Font("Times New Roman", Font.BOLD, 40));
			mainLbl.setForeground(Color.BLACK);
			AdminTitlePanel.add (mainLbl);
		}
		
		public void setFunctionPanel()
		{
			AdminFunctionPanel.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(membercnt);
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(itemschkdout);
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(finesCollected);
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(itemsByCategory);
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(bookCheckedOutMost);
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(logout);
			add(Box.createRigidArea(new Dimension(20,50)));
			AdminFunctionPanel.add(AdminClear);
		
		}
		
		public void setAdminDisplayPanel()
		{
			AdminDisplayPanel.setLayout(new FlowLayout());
			AdminDisplay.setFont(new Font("Times New Roman", Font.BOLD, 17));
			AdminDisplay.setForeground(Color.blue);
			add(Box.createRigidArea(new Dimension(0, 0)));
			AdminDisplayPanel.add(AdminDisplay);
			
		}
		
			
	}

}
